﻿/********************************************************************
	日期:2022/03/27
	名称:AudioSvc
	邮箱:yunnibbd@163.com
	作者:yunni
	描述:声音播放服务
*********************************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioSvc : MonoBehaviour{
    public static AudioSvc Instance;

    public AudioSource bgAudio;
    public AudioSource uiAudio;

    public void InitSvc(){
        Instance = this;
        PECommon.Log("Init AudioSvc...");
    }

    public void PlayBGMusic(string name, bool isLoop = true){
        AudioClip clip = ResSvc.Instance.LoadAudio("ResAudio/" + name, true);
        if (bgAudio.clip == null || bgAudio.clip.name != clip.name){
            bgAudio.clip = clip;
            bgAudio.loop = true;
            bgAudio.Play();
        }
    }

    public void PlayUIMusic(string name){
        AudioClip audio = ResSvc.Instance.LoadAudio("ResAudio/" + name, true);
        uiAudio.clip = audio;
        uiAudio.Play();
    }
}